package com.mingqijia.gassafety.job.strategy.impl;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.mingqijia.gassafety.job.request.UpdateDeviceStateRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class LatestLogInnerServiceImpl {

    @Value("${console.server.externalUrl}")
    private String consoleUrl;

    /**
     * 调用本地设备离线接口
     *
     * @param request
     */
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void LatestLogRequest(List<UpdateDeviceStateRequest> request) {
        try {
            String body = HttpRequest.post(consoleUrl + "/api/inner/v1/latest/log")
                    .header("x-sp-id",request.get(0).getSpId())
                    .body(JSONObject.toJSONString(request))
                    .execute()
                    .body();
            log.info("本地调用结果:{}", body);
        } catch (Exception e) {
            log.error("本地调用结果", e);
        }
    }
}
